package Test3;

import java.lang.reflect.Array;
import java.util.*;

public class demo3 {

    public static void main(String[] args) {
        Map<Character,Integer> map = new HashMap<>();
        String s = "Today, we have a class of Java, as we kown, Java is an object oriented" +
                "  programming language, and Java is fun! Wish you enjoy it!";
        //1.统计次数
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            if(ch==','||ch==' '||ch=='!') continue;
            map.put(ch,map.getOrDefault(ch,0)+1);
        }
        //2.排序
        List<Character> list = new ArrayList<>();
        for(Character tmp:map.keySet()) {
            list.add(tmp);
        }
        Collections.sort(list);
        //3.记录小写字母开始的下标
        int k=0;
        for(;k<list.size();k++) {
            if(list.get(k)>='a'&&list.get(k)<='z') {
                break;
            }
        }
        int p=k;
        //4.顺序打印
            //打印小写字母
        for(;k<list.size();k++) {
            char c = list.get(k);
            System.out.println(c+" -> "+map.get(c));
        }
            //打印大写字母
        for(int i=0;i<p;i++) {
            char c = list.get(i);
            System.out.println(c+" -> "+map.get(c));
        }
    }
}
